<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>轮播-nextTick</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="/VUE/swiper/swiper-bundle.min.css">
    <script src="/VUE/swiper/swiper-bundle.min.js"></script>
    <script src="/VUE/vue2.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .swiper {
            width: 1400px;
            height: 355px;
            margin: 20px auto;
            box-sizing: border-box;
            overflow: hidden;
        }

        .swiper img {
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>
<div id="box">
    <header>导航栏-{{ myname }}</header>

    <div class="swiper">
        <div class="swiper-wrapper">
            <div v-for="item in datalist" class="swiper-slide" :key="item">
                <img :src="item" alt="">
            </div>
        </div>
        <!-- 如果需要分页器 -->
        <div class="swiper-pagination"></div>
    </div>

    <footer>底部内容</footer>
</div>
</body>
<script>
    let vm = new Vue({
        el: "#box",
        data: {
            datalist: [],
            myname: "最爱吃兽奶"
        },

        mounted() {
            setTimeout(() => {
                this.datalist = ["/images/01.jpg", "/images/02.jpg", "/images/03.jpg"]

                this.$nextTick(() => {   // 渲染完成后的一个监听回调函数，只执行一次
                    console.log("我比updated执行都晚，而且只执行一次")
                    new Swiper(".swiper", {

                        loop: true, // 循环模式选项

                        // 如果需要分页器
                        pagination: {
                            el: '.swiper-pagination',
                        },

                        //自动轮播
                        autoplay: {
                            delay: 2500,
                            disableOnInteraction: false,
                        },
                    })
                })

            }, 2000)
        },
        updated() {
            console.log("updated")
        }
    })
</script>
</html>